﻿namespace Hidistro.UI.SaleSystem.CodeBehind
{
    using Hidistro.Entities;
    using Hidistro.Entities.VShop;
    using Hidistro.Membership.Context;
    using Hidistro.SaleSystem.Catalog;
    using Hidistro.SaleSystem.Vshop;
    using Hidistro.UI.Common.Controls;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;

    [ParseChildren(true)]
    public class AliOHDefault : AliOHTemplatedWebControl
    {
        private HtmlImage img;
        private AliOHTemplatedRepeater rptNavigate;
        private AliOHTemplatedRepeater rptProducts;
        private AliOHTemplatedRepeater rptSlide;
        private AliOHTemplatedRepeater rptTopic;

        protected override void AttachChildControls()
        {
            PageTitle.AddSiteNameTitle("首页");
            this.rptSlide = (AliOHTemplatedRepeater) this.FindControl("rptSlide");
            this.rptNavigate = (AliOHTemplatedRepeater) this.FindControl("rptNavigate");
            this.rptTopic = (AliOHTemplatedRepeater) this.FindControl("rptTopics");
            this.rptProducts = (AliOHTemplatedRepeater) this.FindControl("rptProducts");
            this.img = (HtmlImage) this.FindControl("imgDefaultBg");
            if (this.rptSlide != null)
            {
                this.rptSlide.DataSource = VshopBrowser.GetAllBanners(ClientType.AliOH);
                this.rptSlide.DataBind();
            }
            if (this.rptProducts != null)
            {
                DataTable homeProduct = ProductBrowser.GetHomeProduct(ClientType.AliOH);
                this.rptProducts.DataSource = homeProduct;
                this.rptProducts.DataBind();
            }
            if (this.rptTopic != null)
            {
                DataTable topics = VshopBrowser.GetTopics(ClientType.AliOH);
                this.rptTopic.DataSource = topics;
                this.rptTopic.DataBind();
            }
            if (this.rptNavigate != null)
            {
                IList<NavigateInfo> allNavigate = VshopBrowser.GetAllNavigate(ClientType.AliOH);
                foreach (NavigateInfo info in allNavigate)
                {
                    if (!(info.ImageUrl.ToLower().Contains("storage/master/navigate") || info.ImageUrl.ToLower().Contains("templates")))
                    {
                        info.ImageUrl = HiContext.Current.GetAliOHshopSkinPath(null) + "/images/deskicon/" + info.ImageUrl;
                    }
                }
                this.rptNavigate.DataSource = allNavigate;
                this.rptNavigate.DataBind();
            }
            if (this.img != null)
            {
                this.img.Src = new WapTemplateHelper().GetDefaultBg();
            }
        }

        protected override void OnInit(EventArgs e)
        {
            if (this.SkinName == null)
            {
                this.SkinName = "Skin-VDefault.html";
            }
            base.OnInit(e);
        }
    }
}

